package com.tlias.coutroller;

import com.tlias.entity.PageBean;
import com.tlias.entity.Result;
import com.tlias.entity.Student;
import com.tlias.entity.StudentQueryParam;
import com.tlias.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;
    //学员列表查询,用于学员列表数据的条件分页查询
    @GetMapping
    public Result clazzList(StudentQueryParam param) {
        log.info("查询参数:{}", param);
        PageBean  pageBean = studentService.clazzList(param);
        return Result.success(pageBean);
    }
   // 批量删除学员信息
    @DeleteMapping("/{ids}")//@PathVariable可以从URL中获取参数这里前端传来的是这个/students/1,2,3格式可以将1,2,3放到ids集合中进行批量删除
    public Result deleteStudent(@PathVariable  List<Integer> ids) {
        studentService.deleteStudent(ids);
        log.info("批量删除学员信息:{}", ids);
        return Result.success();
    }
    // 新增学员信息
    @PostMapping
    public Result insertStudent(@RequestBody Student student) {
        log.info("新增学员信息:{}", student);
        studentService.insertStudent(student);
        return Result.success();
    }
    //根据主键ID查询学员的信息
    @GetMapping("/{id}")
    public Result getStudent(@PathVariable Integer id) {
        log.info("根据id查询学员信息: {}", id);
        Student student = studentService.getStudent(id);
        return Result.success(student);
    }

    //StudentController
    //修改学员的数据信息
    @PutMapping
    public Result updateStudent(@RequestBody Student student) {
        log.info("修改学员数据信息:{}", student);
        studentService.updateStudent(student);
        return Result.success();
    }
    //违纪处理修改学员的数据信息
    @PutMapping("/violation/{id}/{score}")
    public Result updateStudentViolation(@PathVariable Integer id, @PathVariable Short score) {
        log.info("违纪处理修改学员数据信息:{}", id);
        studentService.updateStudentViolation(id, score);
        return Result.success();
    }
}
